﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using StudentManager.Data.Model;
using StudentManager.Data.IDAL;

namespace StudentManager.API.BLL
{
    public class ZbUserInfoBLL : IZbUserInfoBLL
    {
        private readonly IZbtUserInfoDAL _userDAL;

        public ZbUserInfoBLL(IZbtUserInfoDAL userDAL)
        {
            _userDAL = userDAL;
        }

        public async Task<ZbUserInfo> GetUserByIdAsync(int id)
        {
            return await _userDAL.GetByIdAsync(id);
        }

        public async Task<int> AddUserAsync(ZbUserInfo user)
        {
            // 业务逻辑验证
            if (string.IsNullOrEmpty(user.ZbUserName))
                throw new ArgumentException("用户名不能为空");

            if (string.IsNullOrEmpty(user.ZbPassword))
                throw new ArgumentException("密码不能为空");

            return await _userDAL.AddAsync(user);
        }

        public async Task<bool> UpdateUserAsync(ZbUserInfo user)
        {
            return await _userDAL.UpdateAsync(user);
        }

        public async Task<bool> DeleteUserAsync(int id)
        {
            return await _userDAL.DeleteAsync(id);
        }

        public async Task<(IEnumerable<ZbUserInfo> Users, int TotalCount)> GetPagedListAsync(int pageIndex, int pageSize, string searchKey = "")
        {
            return await _userDAL.GetPagedListAsync(pageIndex, pageSize, searchKey);
        }
    }
}